<!-- 组件：新闻列表 -->
<template>
	<view
		:style="'order:'+Item.order+';'+Item.css"
		class="list-news">
		<template v-if="listState == 'success'">
			<view
				@click="$_To('post/post?pid='+item.pid)"
				v-for="item in list"
				class="for">
				<view class="left">
					<view class="_title">{{item.title?item.title:$_filterHtml(item.content)}}</view>
					<view class="info">
						<view class="info-user">
							<view class="avatar" v-if="!item.isAnonymous">
								<image :src="item.author.avatar" mode="widthFix"></image>
							</view>
							<view
								:style="item.author.nicknameColor?'color:'+item.author.nicknameColor+';opacity:.3;':''"
								class="nickname">
								{{item.isAnonymous?'匿名':item.author.nickname}}
							</view>
						</view>
						<template v-if="item.operations.diversifyImages.length">
							<template v-for="title in item.operations.diversifyImages">
								<template v-if="title.code == 'title'">
									<text
										:style="title.description?title.description+';opacity:.3;':''">
										{{title.name}}
									</text>
								</template>
							</template>
						</template>
						<text v-if="item.group">{{item.group.gname}}</text>
						<text>{{item.commentCount}}评</text>
						<text>{{item.createdTimeAgo}}</text>
					</view>
				</view>
				<view
					v-if="item.files.images.length"
					class="right">
					<image :src="item.files.images[0].imageSquareUrl" mode="widthFix"></image>
				</view>
			</view>
			<view
				v-if="Item.page"
				@click="getList('more')"
				class="more">{{listPageText}}</view>
		</template>
		<template v-if="listState == 'loading'">
			<view class="skeleton-screen" v-for="item in Item.query.pageSize?Item.query.pageSize:1">
				<view class="left loading-css"></view>
				<view class="right loading-css"></view>
			</view>
		</template>
		<template v-if="listState == 'empty'">
			<public-empty></public-empty>
		</template>
	</view>
</template>

<script>
	export default {
		name:"list-news",
		props:{
			Item:{
				type:Object,
				default:null
			},
			YrConfig:{
				type:String,
				default:""
			},
			listGid:{
				type:String,
				default:""
			},
			listHid:{
				type:String,
				default:""
			}
		},
		data() {
			return {
				list:[],
				listState:"loading",
				listPage:2,
				listPageText:"点击加载更多",
			};
		},
		mounted(){
			this.getList();
		},
		// 卸载组件
		destroyed(){
			
		},
		methods: {
			getList(more){
				if(this.Item.query.gid == 'empty'){
					this.Item.query.gid = "";
					this.listGid = ""
				}
				if(this.Item.query.hid == 'empty'){
					this.Item.query.hid = "";
					this.listHid = ""
				}
				if(more == 'more'){
					this.listPageText = "加载中..."
				}
				this.$_Request(
					"GET","/api/v2/post/list",
					{
						"mapId": this.Item.query.mapId,
						"mapLng": this.Item.query.mapLng,
						"mapLat": this.Item.query.mapLat,
						"uidOrUsername": this.Item.query.uidOrUsername,
						"hid": this.Item.query.hid?this.Item.query.hid:this.listHid,
						"gid": this.Item.query.gid?this.Item.query.gid:this.listGid,
						"includeSubgroups": this.Item.query.includeSubgroups,
						"allDigest": this.Item.query.allDigest,
						"digestState": this.Item.query.digestState,
						"stickyState": this.Item.query.stickyState,
						"contentType": this.Item.query.contentType,
						"createdDays": this.Item.query.createdDays,
						"createdDate": this.Item.query.createdDate,
						"createdDateGt": this.Item.query.createdDateGt,
						"createdDateLt": this.Item.query.createdDateLt,
						"likeCountGt": this.Item.query.likeCountGt,
						"likeCountLt": this.Item.query.likeCountLt,
						"followCountGt": this.Item.query.followCountGt,
						"followCountLt": this.Item.query.followCountLt,
						"blockCountGt": this.Item.query.blockCountGt,
						"blockCountLt": this.Item.query.blockCountLt,
						"commentCountGt": this.Item.query.commentCountGt,
						"commentCountLt": this.Item.query.commentCountLt,
						"orderType": this.Item.query.orderType,
						"orderDirection": this.Item.query.orderDirection,
						"blockGroups": this.Item.query.blockGroups + this.YrConfig,
						"blockHashtags": this.Item.query.blockHashtags,
						"pluginRatingId": this.Item.query.pluginRatingId,
						"pageSize": this.Item.query.pageSize,
						"page":more == 'more' ? this.listPage : "",
						"whitelistKeys":"pid,title,content,group.gname,commentCount,createdTimeAgo,files,operations,isAnonymous,author.avatar,author.nickname,author.nicknameColor"
					},
					(res) => {
						if(more == 'more'){
							if(res.data.data.list.length){
								this.list = this.list.concat(res.data.data.list);
								this.listPageText = "点击加载更多";
								this.listPage++
							}else{
								this.listPageText = "没有数据啦"
							}
							this.$store.commit('mutationsStateonReachBottomStatus',true)
						}else{
							if(res.data.data.list.length){
								this.list = res.data.data.list;
								this.listState = "success";
							}else{
								this.listState = "empty"
							}
						}
					}
				)
			}
		},
	}
</script>

<style lang="scss" scoped>
.list-news{
	.for{
		border-bottom: 1rpx solid $BeiJingSe;
		padding: 25rpx 0;
		display: flex;
		.left{
			flex: 1;
			._title{
				display: -webkit-box;
				/*!autoprefixer:off*/
				-webkit-box-orient: vertical;
				/*autoprefixer:on*/
				-webkit-line-clamp: 2;
				overflow: hidden;
			}
			.info{
				margin-top: 15rpx;
				font-size: 22rpx;
				line-height: 22rpx;
				overflow: hidden;
				white-space: nowrap;
				text-overflow: ellipsis;
				display: flex;
				align-items: center;
				text{
					padding-right: 15rpx;
					color: $ZhanWeiSe;
				}
				.info-user{
					display: flex;
					align-items: center;
					.avatar{
						width: 25rpx;
						height: 25rpx;
						overflow: hidden;
						border-radius: 100%;
						margin-right: 5rpx;
					}
					.nickname{
						font-size: 22rpx;
						line-height: 22rpx;
						color: $ZhanWeiSe;
						margin-right: 15rpx;
					}
				}
			}
		}
		.right{
			width: 200rpx;
			height: 145rpx;
			overflow: hidden;
			border-radius: 10rpx;
			box-shadow: 0 0 1rpx $ZhanWeiSe;
			margin-left: 20rpx;
			background: $BeiJingSe;
		}
	}
	.more{
		display: flex;
		align-items: center;
		justify-content: center;
		font-size: 28rpx;
		line-height: 28rpx;
		color: $ZhanWeiSe;
		padding: 35rpx 0;
	}
}
.skeleton-screen{
	display: flex;
	border-bottom: 1rpx solid $BeiJingSe;
	padding: 25rpx 0;
	.left{
		flex: 1;
		height: 145rpx;
		margin-right: 20rpx;
	}
	.right{
		width: 200rpx;
		height: 145rpx;
	}
}
</style>